package com.mapapp.flutter_mapapp.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.mapapp.flutter_mapapp.R;

import java.util.List;

public class PhotoAdapter extends RecyclerView.Adapter<PhotoAdapter.ClockShopViewHolder>{

    private List<Bitmap> mPhotos;
    private Context mContext;

    public PhotoAdapter(List<Bitmap> photos , Context content){
        this.mPhotos = photos;
        this.mContext = content;
    }

    public void notify(List<Bitmap> photos){
        this.mPhotos = photos;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ClockShopViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_photo, parent, false);
        ClockShopViewHolder holder = new ClockShopViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ClockShopViewHolder holder, final int position) {
        Bitmap bitmap = mPhotos.get(position);
        holder.pic.setImageBitmap(bitmap);
    }

    @Override
    public int getItemCount() {
        if (mPhotos == null) {
            return 0;
        }
        return mPhotos.size();
    }

    static class ClockShopViewHolder extends RecyclerView.ViewHolder {
        private ImageView pic;

        public ClockShopViewHolder(View itemView) {
            super(itemView);
            pic = itemView.findViewById(R.id.iv_item_photo);
        }
    }

}
